package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.problem.ControlProblemFindingQueryDTO;
import com.bf.electroplating.pojo.dto.problem.ControlProblemRectificationDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.problem.ControlProblemFindingVO;
import com.bf.electroplating.pojo.vo.problem.ControlProblemRectificationVO;
import com.bf.electroplating.service.ControlProblemRectificationService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "问题发现整改")
@RestController
@RequestMapping("/controlProblemRectification")
public class ControlProblemRectificationController {

    @Resource
    private ControlProblemRectificationService controlProblemRectificationService;

    @Operation(summary = "分页查询")
    @PostMapping("/page")
    public ResultVO<Page<ControlProblemFindingVO>> page(@RequestBody ControlProblemFindingQueryDTO dto) {
        return ResultVO.ok(controlProblemRectificationService.pageList(dto));
    }

    @Operation(summary = "查看")
    @PostMapping("/detail")
    public ResultVO<ControlProblemRectificationVO> detail(@RequestBody IdDTO id) {
        return ResultVO.ok(controlProblemRectificationService.detail(id.getId()));
    }

    @Idempotent
    @Operation(summary = "整改")
    @PostMapping("/rectification")
    public ResultVO<Void> rectification(@Validated @RequestBody ControlProblemRectificationDTO dto) {
        controlProblemRectificationService.rectification(dto);
        return ResultVO.ok(null,"编辑成功");
    }

}
